package edu.jmu.action.permanage;

import java.io.Serializable;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import edu.jmu.action.BaseAction;
import edu.jmu.bean.PageView;
import edu.jmu.bean.user.Branch;
import edu.jmu.service.sysmanage.PrivilegeService;
import edu.jmu.service.user.BranchService;


@Controller
@Scope(value="prototype")
public class BranchManageAction extends BaseAction<Branch> {
	private static final long serialVersionUID = 1383472981530612768L;
	
	@Resource
	private BranchService branchService;
	private PrivilegeService privilegeService;
	private Branch branch;
	private Integer[] delId;
	
//	ManualSign manualSign = (ManualSign) em.createQuery(jpql).setParameter(1, dutytime1).setParameter(2, dutytime2).getSingleResult();	
//	@Permission(module="permanage",privilege="listBranch",desc="展示机构列表")
	public String listBranch(){
		pageView = new PageView<Branch>(maxresult,currentpage);
		pageView.setQueryResult(branchService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult()));
		return SUCCESS;
	}
	
//	@Permission(module="role",privilege="addBranch",desc="添加机构")
	public String addBranch(){		
		branchService.save(branch);
		return SUCCESS;
	}
	
	@SkipValidation
	@Action(value="showBranch" ,results={
			@Result(location="/page/permanage/editBranch.jsp"),
			@Result(name=INPUT,location="/page/permanage/editBranch.jsp")
	})
//	@Permission(module="branch",privilege="showBranch",desc="展示机构")
	public String showBranch(){
		if(branch.getId() == null || ("").equals(branch.getId())){
			return INPUT;
		}
		this.branch = branchService.find(branch.getId());
		return SUCCESS;
	}
	
	//批量的删除
	public String deleteBranch(){
		branchService.delete((Serializable[])delId);
		return SUCCESS;
	}
	
	public String updateBranch(){
		branchService.update(branch);
		return SUCCESS;
	}

	
	public Branch getBranch() {
		return branch;
	}

	public void setBranch(Branch branch) {
		this.branch = branch;
	}

	public void setDelId(Integer[] delId) {
		this.delId = delId;
	}
	
}
